package com.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class QueryData {
	public static void main(String[] args) throws ClassNotFoundException, SQLException{
		
	
		String driver = "com.mysql.jdbc.Driver";


		// URL指向要访问的数据库名

		String url = "jdbc:mysql://192.168.8.177:3306/mysqldb_memberdb?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=round";

		// MySQL配置时的用户名

		String user = "dbu_memberdb";

		// Java连接MySQL配置时的密码

		String password = "w!3k9i3s";

		// 加载驱动程序
		Class.forName(driver);
		
		// 连续数据库
		Connection conn = DriverManager.getConnection(url, user, password);
		
		String sql = "select e1.id,e1.manid,e2.firstname,e2.marry as marr,e2.country from info_core e1,info_basic e2 where e1.manid=e2.manid and e1.manid='CM100010' LIMIT 1";
		
		PreparedStatement pre = conn.prepareStatement(sql);
		
		ResultSet rs = pre.executeQuery();
		
		while(rs.next()){
			//System.out.println(rs.getObject("marr"));
			System.out.println(rs.getString("id"));
			System.out.println(rs.getString("country"));
			
		}
		
		if(rs!=null){
			rs.close();
		}
		
		if(pre!=null){
			pre.close();
		}
		
		if(conn!=null){
			conn.close();
		}
		
	}

}
